package com.sskj.gocoin.v.activity;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.common.rxbus2.RxBus;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.m.bean.UserInfo;
import com.sskj.gocoin.p.activity.PersonalPresenter;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.gocoin.v.base.BaseActivity;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * <pre>
 *     author : 李岩
 *     e-mail : 465357793@qq.com
 *     time   : 2018/04/03
 *     desc   : 个人中心
 *     version: 1.0
 * </pre>
 */
public class PersonalActivity extends BaseActivity<PersonalPresenter> {


    @BindView(R2.id.toolbar)
    ToolBarLayout toolBar;
    @BindView(R2.id.personal_mobile)
    TextView personalMobile;
    @BindView(R2.id.personal_email)
    TextView personalEmail;
    @BindView(R2.id.personal_trabcaction_id)
    TextView personalTrabcactionId;
    @BindView(R2.id.personal_name)
    TextView personalName;
    @BindView(R2.id.personal_ident)
    TextView personalIdent;
    @BindView(R2.id.textView26)
    TextView textType;  // 手机号还是邮箱
    @BindView(R2.id.personal_logout)
    Button logout;
    @BindView(R2.id.security_vip_checked)
    TextView mSecurityVipChecked;
    @Inject
    UserViewModel userViewModel;
    private UserData userData;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_personal;
    }

    @Override
    public PersonalPresenter getPresenter() {
        return new PersonalPresenter();
    }

    @Override
    protected void onViewBinding() {
        toolBar.setTitle(App.INSTANCE.getString(R.string.strPersonalActivity200));
        toolBar.setLeftButtonText(App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity1));
        toolBar.setLeftButtonOnClickLinster(v -> finish());
        ClickUtil.click(logout, () -> {
            RxBus.getDefault().send(Constants.USER_LOGOUT);
            SPUtils.clear(MyAppLication.getMobile());
            ARouter.getInstance().build(RConfig.APP_LOGIN).navigation();
            overridePendingTransition(R.anim.lib_anim_in, R.anim.lib_anim_out);

            finish();
        });
    }

    @Override
    protected void initData() {
        mPresenter.getUserInfo();
    }

    public void updateUserInfo(UserInfo userInfo) {
        setText(personalEmail, userInfo.getMail());
        setText(personalMobile, userInfo.getMobile());
        setText(personalIdent, userInfo.getIdcard());
        setText(personalName, userInfo.getRealname());
        setText(personalTrabcactionId, userInfo.getAccount());
        if (userInfo != null) {
            if (userInfo.getWallone() >= userInfo.getMoney1()) {
                setText(mSecurityVipChecked, App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity2) + userInfo.getFree_fee1() + "%");
            }
            if (userInfo.getWallone() >= userInfo.getMoney2()) {
                setText(mSecurityVipChecked, App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity4) + userInfo.getFree_fee2() + "%");
            }
            if (userInfo.getWallone() >= userInfo.getMoney3()) {
                setText(mSecurityVipChecked, App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity6) + userInfo.getFree_fee3() + "%");
            }
            if (userInfo.getWallone() >= userInfo.getMoney4()) {
                setText(mSecurityVipChecked, App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity8) + userInfo.getFree_fee4() + "%");
            }
            if (userInfo.getWallone() >= userInfo.getMoney5()) {
                setText(mSecurityVipChecked, App.INSTANCE.getString(R.string.fabimineJavaPersonalActivity10) + userInfo.getFree_fee5() + "%");
            }

        }

    }
}
